package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Repair;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.RepairService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class RepairController {
    @Resource
    RepairService repairService;

    @PostMapping("/repair/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Repair>>  getAllRepairByPage(@PathVariable("pageIndex") int pageIndex,
                                                                @PathVariable("pageSize") int pageSize,
                                                                @RequestBody Repair repair){
        System.out.println(repair);
        PageBean<Repair> pageBean = repairService.getRepairByPage(pageIndex, pageSize, repair);
        return  new ResponseResult<>(200, "ok", pageBean);
    }


    @PostMapping("/repair")
    public ResponseResult<Repair> addRepair(@RequestBody Repair repair){
        System.out.println("添加报修："+repair);
        repairService.insertRepair(repair);
        return new ResponseResult<>(200, "ok",null);
    }

    @PutMapping("/repair")
    public ResponseResult<Repair> modifyRepair(@RequestBody Repair repair){
        System.out.println("修改报修："+repair);
        repairService.updateRepair(repair);
        return new ResponseResult<>(200, "ok",null);
    }

    @DeleteMapping("/repair/{repairid}")
    public ResponseResult<Repair> removeRepair(@PathVariable("repairid") int repairid){
        System.out.println("删除报修："+repairid);
        repairService.deletRepair(repairid);
        return new ResponseResult<>(200, "ok",null);
    }
}
